package com.fanshuai2.niuke.strings;

import java.util.Scanner;

public class StringMatch {
    static boolean match(String pattern, String text) {
        return match(pattern, text, 0, 0);
    }

    static boolean match(String pattern, String text, int i, int j) {
        if (i >= pattern.length() && j >= text.length()) {
            return true;
        }
        if (i >= pattern.length() || j >= text.length()) {
            return false;
        }

        char ch = pattern.charAt(i);
        char ch2 = text.charAt(j);
        if (ch == '?') {
            if (!Character.isDigit(ch2) && !Character.isLetter(ch2)) {
                return false;
            }
            return match(pattern, text, i + 1, j + 1);
        } else if (ch == '*') {
            while (i < pattern.length() && pattern.charAt(i) == '*') {
                i++;
            }
            i--;

            return match(pattern, text, i + 1, j) ||
                    match(pattern, text, i + 1, j + 1) ||
                    match(pattern, text, i, j + 1);
        } else {
            boolean equal = Character.toLowerCase(ch) == Character.toLowerCase(ch2);
            if (equal) {
                return match(pattern, text, i + 1, j + 1);
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNextLine()) {
            String pattern = in.nextLine();
            String text = in.nextLine();
            System.out.println(match(pattern, text));
        }
    }
}
